'''
python如何操作文件：
txt文件：掌握一下
csv文件：重点掌握
json文件：掌握一下
yaml文件：重点掌握
xlxs文件：了解

python 基础文件操作：
open():
close():
read():
write():

'''
#   例1  读
f = open(r'username.txt')
data = f.read()
print(data)
f.close()
#   例2  读
with open(r'username.txt') as f:
    data = f.read()
    print(data)
#   例3  写
with open(r'test.txt',mode='w') as f:
    str = 'hello world'
    f.write(str)
#   例4  图片
with open(r'caomei.png',mode='rb') as f1,open(r'caomei1.png',mode='wb') as f2:
    data = f1.read()
    f2.write(data)


